// 文章回复
const { getAll, getCount, add, remove } = require('../utils/dbTools');
const tableName = 'reply'

/**
 * 获取文章回复列表 
 * @param {object} map 查询条件
 * @return {array} 回复列表
 */
const getReplyList = async (map) => {
    if (!map) return false
    const result = await getAll(tableName, map)
    return result
}
/**
 * 获取文章回复总数
 * @param {object} map 查询条件
 * @return {number} 回复总数
 */
const getReplyTotal = async (map) => {
    if (!map) return false
    const result = await getCount(tableName, map)
    return result
}

/**
 * 发布回复 
 * @parma {object} params 回复参数
 * @param {number}  回复id
 */
const addReply = async (params) => {
    if (!params) return false
    const result = await add(params, tableName)
    return result && result.insertId
}

/**
 * 删除回复 
 * @param {number} id 回复参数
 * @param {boolean} 是否删除成功
 */
const removeReply = async (id) => {
    if (!id) return false
    const result = await remove(id, tableName)
    return result
}


module.exports = {
    getReplyList, getReplyTotal, addReply, removeReply
}